package com.qire.manhua.activity;

import android.os.Bundle;
import android.view.View;

import com.qire.antscore.annotation.RouteMapping;
import com.qire.antsrouter.inject.Autowired;
import com.qire.common.constant.Navigation;
import com.qire.common.inject.EventControllerInjector;
import com.qire.common.inject.ViewModelInjector;
import com.qire.common.support.base.BaseActivity;
import com.qire.common.utils.ThemeUtil;
import com.qire.common.widget.animation.SimpleAnimationUtil;
import com.qire.manhua.R;
import com.qire.manhua.controller.ComicReaderFinishController;
import com.qire.manhua.databinding.ActivityComicReaderFinishBinding;
import com.qire.manhua.model.viewModel.impl.ComicReaderFinishViewModel;

import androidx.annotation.Nullable;

@RouteMapping(path = Navigation.Page.ComicReaderFinishPage)
public class ComicReaderFinishActivity extends BaseActivity<ActivityComicReaderFinishBinding> {

    @Autowired
    int comicBookId;

    @Autowired(injector = ViewModelInjector.class)
    ComicReaderFinishViewModel viewModel;

    @Autowired(injector = EventControllerInjector.class)
    ComicReaderFinishController controller;

    @Override
    public int layoutRid() {
        return R.layout.activity_comic_reader_finish;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ThemeUtil.setWindowGravityBottom(this, 0f);
        SimpleAnimationUtil.playAnimationOnView(this, R.anim.app_dialog_bottom_in, viewDataBinder().scrollView, null);

        viewModel.onAddition();
        controller.onAddition(viewModel);

        viewModel.loadData(comicBookId);
    }

    @Override
    public void finish() {
        final ActivityComicReaderFinishBinding viewDataBinder = viewDataBinder();

        SimpleAnimationUtil.playAnimationOnView(this, R.anim.app_quick_read_topbar_out, viewDataBinder.comicTitlePanel, animation -> {
            viewDataBinder.comicTitlePanel.setVisibility(View.GONE);
        });

        SimpleAnimationUtil.playAnimationOnView(this, R.anim.app_dialog_bottom_exit, viewDataBinder.scrollView, animation -> {
            super.finish();
            overridePendingTransition(0, 0);//结束的动画
        });
    }

}
